package com.sds.replicator.servlets;

import com.google.inject.Singleton;
import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * Created by IntelliJ IDEA.
 * User: sdsbirdman
 * Date: 6/26/11
 * Time: 12:18 AM
 * To change this template use File | Settings | File Templates.
 */
@Singleton
public class TestServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest incomingRequest, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().println(incomingRequest.getRequestURL().toString());
        resp.getWriter().println(incomingRequest.getPathInfo());
        resp.getWriter().println(incomingRequest.getQueryString());
        resp.getWriter().println(incomingRequest.getPathInfo() + "?" + incomingRequest.getQueryString());

        Enumeration enumeration = incomingRequest.getHeaderNames();
        while (enumeration.hasMoreElements()) {
            String name = enumeration.nextElement().toString();
            resp.getWriter().println(name + "=" + incomingRequest.getHeader(name));
        }

        ServletInputStream in = incomingRequest.getInputStream();
        IOUtils.copy(in,resp.getWriter());
    }
}
